<?php
session_start();
error_reporting(0);
if($_SESSION['username']!="")
{
?>
<!DOCTYPE html>
<html lang="en">
 <head>
     <? include "./include/head.php"; ?>
	  <? include "./include/js.php"; ?>
  </head>
  <body>
  <? include "./include/body.php"; ?>
		<?php

		include "./config/connection.php";
		include "./config/function_thumb.php";
 
		$id_produk = trim($_POST['id_produk']);
		$nama_produk = $_POST['nama_produk'];
		$komposisi = $_POST['komposisi'];
		$kemasan = $_POST['kemasan'];
		$berat = $_POST['berat'];
		$harga = $_POST['harga'];
		$lokasi_file = $_FILES['foto']['tmp_name'];
		$nama_file   = $_FILES['foto']['name'];

		if(empty($id_produk) || empty($nama_produk) || empty($berat) || empty($harga) || empty($nama_file)){
			header ("location:product_add.php?page=input&input=invalid");
		}
		else{	
			$exec="INSERT INTO produk(id_produk,nama_produk,komposisi,kemasan,berat,harga,foto) 
			VALUES('$id_produk',
					'$nama_produk',
					'$komposisi',
					'$kemasan',
					'$berat',
					'$harga',
					'$nama_file')";

		$sukses_insert = mysql_query($exec);
		if($sukses_insert){
			UploadProduk($nama_file);
			echo"<script>alert('Data Berhasil Ditambah ')</script>";
			echo"<script>history.go(-2);</script>";
		}
		else{
			header ("location:product_add.php?input=invalid");
		} 
	}

?>
 <? include "./include/menubawah.php"; ?>
    
  </body>
</html>
<?php
    }
else {
    include 'warning.php';
}
?>